package team18.yuejian.Activity;

import android.content.Intent;
import android.service.quicksettings.Tile;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import team18.yuejian.Adapter.MineFocusAdapter;
import team18.yuejian.Adapter.MineListAdapter;
import team18.yuejian.Adapter.ShowPicAdapter;
import team18.yuejian.Model.MineModel;
import team18.yuejian.R;
import team18.yuejian.RetrofitListener;
import team18.yuejian.bean.FocusBean;
import team18.yuejian.bean.NoteBean;
import team18.yuejian.bean.OrderBean;
import team18.yuejian.bean.PicBean;

public class MineListActivity extends BaseActivity implements View.OnClickListener,RetrofitListener {

    private int mflag,uid,delete;
    private TextView Title;
    private ImageView back;
    private RecyclerView recyclerView;
    private ShowPicAdapter showPicAdapter;
    private MineFocusAdapter mineFocusAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mine_list);
        initView();
        initEvent();
        initData();
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.MineList_back:
                MineListActivity.this.finish();
                break;
        }

    }

    @Override
    public void onSuccess(Object o, int flag) {
        int i = flag;

        if (mflag==2){
            if (i == 8){
                GridLayoutManager layoutManager = new GridLayoutManager(this,1);
                recyclerView.setLayoutManager(layoutManager);
                mineFocusAdapter = new MineFocusAdapter(((List<FocusBean>) o));
                recyclerView.setAdapter(mineFocusAdapter);
            }else if (i == 9){
                Toast.makeText(MineListActivity.this,((NoteBean)o).getMsg(),Toast.LENGTH_SHORT).show();
                MineListActivity.this.finish();
                Intent intent = new Intent(MineListActivity.this,MineActivity.class);
                startActivity(intent);
            }

        }else if (mflag == 3){
            if (i == 6){
                GridLayoutManager layoutManager = new GridLayoutManager(this,2);
                recyclerView.setLayoutManager(layoutManager);
                showPicAdapter = new ShowPicAdapter(((List<PicBean>) o),2);
                recyclerView.setAdapter(showPicAdapter);
            }else if (i==7){
                Toast.makeText(MineListActivity.this,"success",Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(MineListActivity.this,MineActivity.class);
                startActivity(intent);
            }
        }
    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(MineListActivity.this,msg,Toast.LENGTH_SHORT).show();
    }

    public void initView(){
        Title = findViewById(R.id.MineList_Title);
        back = findViewById(R.id.MineList_back);
        recyclerView = findViewById(R.id.MineList_recycle_view);

    }

    public void initEvent(){
        back.setOnClickListener(this);
    }

    public void initData(){
        Intent intent = getIntent();
        uid = getUserId();
        mflag = intent.getIntExtra("type",0);
        delete = intent.getIntExtra("delete",-1);
        if (mflag==2){
            Title.setText("我的关注");
            MineModel mineModel = new MineModel();
            mineModel.MineFocus(uid,this);
            if (delete!=-1){
                MineModel mineModel1 = new MineModel();
                mineModel1.MineDeleteFocus(uid,delete,this);
            }
        }else if (mflag==3){
            Title.setText("我的晒图");
            MineModel mineModel = new MineModel();
            mineModel.MineGetShowPic(uid,this);
            if (delete!=-1){
                MineModel mineModel1 = new MineModel();
                mineModel1.MineDeletePic(uid,delete,this);
            }
        }
    }



}
